package com.west_traveler.fragment;

import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.text.format.Formatter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.west_traveler.viewpager_adapter.DownloadPageViewPagerAdapter;
import com.west_traveler.ximalayafm.R;

import java.io.File;

/**
 * Description: 下载听Fragment
 * Date:2016年12月02日15:10
 *
 * @author: 刘悦.
 */

public class DownloadFragment extends Fragment {


    private TabLayout tabLayout;
    private TextView tvFreeSize;
    private ViewPager viewPager;
    private Context mContext;

    public static DownloadFragment getInstance() {
        return new DownloadFragment();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_download, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        mContext = getContext();

        initView(view);

        tabLayout.setupWithViewPager(viewPager);

        File rootDirectory = Environment.getExternalStorageDirectory();
        long freeSpace = rootDirectory.getFreeSpace();
        String freeSize = Formatter.formatFileSize(mContext, freeSpace);
//        ximalaya.get
        tvFreeSize.setText("已占用0.00B,可用" + freeSize);

        String[] tabNames = getResources().getStringArray(R.array.download_page_tab_names);

        DownloadPageViewPagerAdapter adapter = new DownloadPageViewPagerAdapter(getChildFragmentManager(), tabNames);

        viewPager.setAdapter(adapter);

    }

    private void initView(View view) {
        tabLayout = (TabLayout) view.findViewById(R.id.tb_download_id);
        tvFreeSize = (TextView) view.findViewById(R.id.tv_download_free_size_id);
        viewPager = (ViewPager) view.findViewById(R.id.vp_download_id);
    }


}
